home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / rotise12.zip / ROSTER.C < prev    next >
Text File  |  1993-03-28  |  9KB  |  382 lines

  1. /* roster.c
  2.     Jonathan Arnold 1991
  3.  
  4.     Commands to create leagues and rosters.  These function are usually
  5.     only run before the first interval.
  6.     For instance:
  7.         league - Describe league
  8.         team - describe a team
  9.         create - Create a new player in player database
  10.         add - add a player to a rotisserie team
  11.         minors - add a player to rotisserie team's minors
  12. */
  13.  
  14. #include <string.h>
  15.  
  16. #ifdef __TURBOC__
  17. #include <alloc.h>
  18. #else
  19. #include <malloc.h>
  20. #endif
  21.  
  22. #include "rotise.h"
  23.  
  24. #include "rdb.h"
  25.  
  26. /* External data referenced */
  27. extern BOOL Verbose;                            /* rotise.c */
  28. extern int Cmd;
  29. extern int InputLine;
  30. extern char *InputFilename;
  31. extern CMDLIST CmdTable[];                    /* cmdtable.c */
  32.  
  33. /* External routines used */
  34.     /* NONE */
  35.  
  36. /* Local data publicly available */
  37. RDB_TEAM *RotoTeams = NULL;                /* First team in list */
  38. int RotoTeamCnt = 0;                            /* How many teams in League */
  39. RDB_TEAM *LastTeam = NULL;                    /* Current end of list */
  40. char LeagueName[MAX_LEAGUESIZE];            /* Name of league */
  41.  
  42. /* Local routine prototypes */
  43.     /* NONE */
  44.  
  45. /* Private data */
  46.     /* NONE */
  47.  
  48. /*
  49.     BOOL league( int tokcnt, char *tokens[] )
  50.      Describe the league in one line of 80 characters or less.  Can be
  51.     anything you want.
  52.  
  53.  ACCEPTS:
  54.     int tokcnt - how many tokens on this line
  55.     char *tokens[] - array pointing to each token
  56.  
  57.  RETURNS:
  58.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  59. */
  60.  
  61. BOOL league ARGLIST( (tokcnt, tokens) )
  62.     NFARG( int tokcnt )
  63.     FARG( char *tokens[] )
  64. {
  65.     int argcnt;
  66.  
  67.     if ( tokcnt < 2 )
  68.         ARGCNT_ERR();
  69.  
  70.     for ( argcnt = 1; argcnt < tokcnt; argcnt++ )
  71.     { /* add to league name */
  72.         if ( (strlen(LeagueName) + strlen(tokens[argcnt])) > MAX_LEAGUESIZE )
  73.         { /* too big */
  74.             fprintf( stderr, "!WARNING!League name truncated.\n" );
  75.             return TRUE;
  76.         }
  77.  
  78.         strcat( LeagueName, " " );
  79.         strcat( LeagueName, tokens[argcnt] );
  80.     }
  81.  
  82.     return TRUE;
  83. }
  84. /*
  85.     BOOL team( int tokcnt, char *tokens[] )
  86.      Describe a team.  Give it a Rotisserie Keyword and a name.
  87.  
  88.  ACCEPTS:
  89.     int tokcnt - how many tokens on this line
  90.     char *tokens[] - array pointing to each token
  91.  
  92.  RETURNS:
  93.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  94. */
  95.  
  96. BOOL team ARGLIST( (tokcnt, tokens) )
  97.     NFARG( int tokcnt )
  98.     FARG( char *tokens[] )
  99. {
  100.     int argcnt;
  101.  
  102.     if ( tokcnt < 3 )
  103.         ARGCNT_ERR();
  104.  
  105.     if ( RotoTeams == NULL )
  106.     { /* First one */
  107.         RotoTeams = (RDB_TEAM *)calloc( 1, sizeof( RDB_TEAM ) );
  108.         LastTeam = RotoTeams;
  109.     }
  110.     else
  111.     { /* add to end of list */
  112.         LastTeam->next = (RDB_TEAM *)calloc( 1, sizeof( RDB_TEAM ));
  113.         LastTeam = LastTeam->next;
  114.     }
  115.  
  116.     if ( LastTeam == NULL )
  117.     { /* problems */
  118.         fprintf( stderr, "Ran out of memory.\n" );
  119.         return FALSE;
  120.     }
  121.  
  122.     /* One more team */
  123.     RotoTeamCnt++;
  124.  
  125.     /* get key */
  126.     strncpy( LastTeam->key, tokens[1], sizeof( LastTeam->key )-1 );
  127.  
  128.     /* now get the team name */
  129.     for ( argcnt = 2; argcnt < tokcnt; argcnt++ )
  130.     { /* add strings to end of name */
  131.  
  132.         if ( argcnt != 2 )
  133.             strcat( LastTeam->name, " " );
  134.  
  135.         if ( (strlen( LastTeam->name ) + strlen( tokens[argcnt] )) > MAX_TEAMSIZE )
  136.         { /* too long a string */
  137.             break;
  138.         }
  139.  
  140.         strcat( LastTeam->name, tokens[argcnt] );
  141.     }
  142.     return TRUE;
  143. }
  144. /*
  145.     BOOL owner( int tokcnt, char *tokens[] )
  146.      Describe a team's owner(s).
  147.  
  148.  ACCEPTS:
  149.     int tokcnt - how many tokens on this line
  150.     char *tokens[] - array pointing to each token
  151.  
  152.  RETURNS:
  153.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  154. */
  155.  
  156. BOOL owner ARGLIST( (tokcnt, tokens) )
  157.     NFARG( int tokcnt )
  158.     FARG( char *tokens[] )
  159. {
  160.     RDB_TEAM *rteam;
  161.     int argcnt;
  162.  
  163.     if ( tokcnt < 3 )
  164.         ARGCNT_ERR();
  165.  
  166.     VERBOSE( 5, "\Owner of %s", tokens[1] );
  167.     VERBOSE( 5, " is %s.\n", tokens[2] );
  168.  
  169.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  170.     { /* find the team */
  171.         if ( strcmp( rteam->key, tokens[1] ) == 0 )
  172.             break;
  173.     }
  174.  
  175.     if ( rteam == NULL )
  176.     { /* couldn't find it */
  177.         rdb_error( "Owner  - Team Keyword Not Found: ", tokens[1] );
  178.         return TRUE;
  179.     }
  180.  
  181.     /* now get the owner name */
  182.     for ( argcnt = 2; argcnt < tokcnt; argcnt++ )
  183.     { /* add strings to end of name */
  184.  
  185.         if ( argcnt != 2 )
  186.         { /* tack on a space */
  187.             strcat( rteam->owner, " " );
  188.         }
  189.  
  190.         if ( (strlen( rteam->owner ) + strlen( tokens[argcnt] )) > MAX_TEAMSIZE )
  191.         { /* too long a string */
  192.             break;
  193.         }
  194.  
  195.         strcat( rteam->owner, tokens[argcnt] );
  196.     }
  197.     return TRUE;
  198. }
  199. /*
  200.     BOOL add( int tokcnt, char *tokens[] )
  201.      Add player to a rotisserie teams's roster.  Creates the player
  202.        entry in the player database if necessary.
  203.  
  204.  ACCEPTS:
  205.     int tokcnt - how many tokens on this line
  206.     char *tokens[] - array pointing to each token
  207.  
  208.  RETURNS:
  209.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  210. */
  211.  
  212. BOOL add ARGLIST( (tokcnt, tokens) )
  213.     NFARG( int tokcnt )
  214.     FARG( char *tokens[] )
  215. {
  216.     RDB_TEAM *rteam;
  217.     RDB_PLAYER *rplayer, *wplayer;
  218.     PDB_PNAME nameblk;
  219.  
  220.     VERBOSE( 5, "\tAdding to %s", tokens[1] );
  221.     VERBOSE( 5, " %s.\n", tokens[2] );
  222.  
  223.     for ( rteam = RotoTeams; rteam != NULL; rteam = rteam->next )
  224.     { /* find the team */
  225.         if ( strcmp( rteam->key, tokens[1] ) == 0 )
  226.             break;
  227.     }
  228.  
  229.     if ( rteam == NULL )
  230.     { /* couldn't find it */
  231.         rdb_error( "Add  - Team Keyword Not Found: ", tokens[1] );
  232.         return TRUE;
  233.     }
  234.  
  235.     rplayer = (RDB_PLAYER *)calloc( 1, sizeof( RDB_PLAYER ) );
  236.  
  237.     if ( rplayer == NULL )
  238.     { /* couldn't get memory */
  239.         fprintf( stderr, "Unable to get memory.\n" );
  240.         return FALSE;
  241.     }
  242.  
  243.     if ( rdb_add_player( rplayer, tokcnt, tokens ) == FALSE )
  244.     { /* had problems, free it up */
  245.         free( rplayer );
  246.     }
  247.     else
  248.     { /* worked just fine, add to list */
  249.         if ( rteam->players == NULL )
  250.         { /* first player */
  251.             rteam->players = rplayer;
  252.         }
  253.         else
  254.         { /* find last one */
  255.             for ( wplayer = rteam->players; wplayer->next != NULL; wplayer = wplayer->next )
  256.             { /* skip through the list */
  257.             }
  258.             wplayer->next = rplayer;
  259.         }
  260.         rplayer->start = 1;
  261.         rplayer->end = 1;
  262.  
  263.         rteam->money_spent += rplayer->salary;
  264.  
  265.  
  266.         /* Now make sure the player is in the player database. */
  267.         strcpy( &nameblk.pn_lname[0], &rplayer->pname.pn_lname[0] );
  268.         strcpy( &nameblk.pn_fname[0], &rplayer->pname.pn_fname[0] );
  269.         strcpy( &nameblk.pn_team[0], &rplayer->pname.pn_team[0] );
  270.         nameblk.batter = ( slot_get( rplayer->slot )->slot[0] != 'P' );
  271.  
  272.         if ( !pdb_create_player( &nameblk ) )
  273.         { /* Couldn't create */
  274.             fprintf( stderr, "add: Can't create player data for %s, %s\n",
  275.                         &nameblk.pn_lname[0], &nameblk.pn_fname[0] );
  276.         }
  277.         else
  278.         { /* Mark the guy not free */
  279.             pdb_status( &nameblk, "", "", PLAYER_CLAIMED, 1 );
  280.         }
  281.         
  282.     }
  283.  
  284.     return TRUE;
  285. }
  286. /*
  287.     BOOL create( int tokcnt, char *tokens[] )
  288.      Create a player.  This is used when a player is needed but has
  289.       not yet been registered to the player database via stat files.
  290.       E.g., claiming somebody who hasn't yet played.
  291.  
  292.  ACCEPTS:
  293.     int tokcnt - how many tokens on this line
  294.     char *tokens[] - array pointing to each token
  295.  
  296.  RETURNS:
  297.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  298. */
  299.  
  300. #define    ARG_CRE_PK1        1                        /* Player key, last name */
  301. #define    ARG_CRE_PK2        2                        /* Player key, first name/initial */
  302. #define    ARG_CRE_POS        3                        /* Position list */
  303.  
  304. BOOL create ARGLIST( (tokcnt, tokens) )
  305.     NFARG( int tokcnt )
  306.     FARG( char *tokens[] )
  307. {
  308.     int            i;
  309.     UWORD            m;
  310.     UWORD            posmask;
  311.     PDB_PNAME    nameblk;
  312.     PDATA            *pdata;
  313.  
  314.     VERBOSE( 5, "\tCreating player %s", tokens[ARG_CRE_PK1] );
  315.     VERBOSE( 5, " %s.\n", tokens[ARG_CRE_PK2] );
  316.  
  317.     /* Make sure there are enough tokens */
  318.     if ( tokcnt < ARG_CRE_PK2 )
  319.         ARGCNT_ERR();
  320.  
  321.     /* Make position eligibility mask from position args */
  322.     for( posmask = 0, i = ARG_CRE_POS; i < tokcnt; ++i )
  323.     {
  324.         m = pos_to_mask( tokens[i] );
  325.         if ( m == 0 )
  326.         {    /* Position not recognized */
  327.             rdb_error( "Unknown position: ", tokens[i] );
  328.         }
  329.         else
  330.             posmask |= m;
  331.     }
  332.  
  333.     /* Build player block and create the player */
  334.     strcpy( &nameblk.pn_lname[0], strupr(tokens[ARG_CRE_PK1]) );
  335.     strcpy( &nameblk.pn_fname[0], strupr(tokens[ARG_CRE_PK2]) );
  336.     strcpy( &nameblk.pn_team[0], "" );
  337.     nameblk.batter = ( ( posmask & POS_P ) == 0 );
  338.  
  339.     if ( !pdb_create_player( &nameblk ) )
  340.     {    /* Can't make 'im */
  341.         rdb_error( "Can't create ", &nameblk.pn_lname[0] );
  342.     }
  343.  
  344.     pdata = pdb_pdata( tokens[ARG_CRE_PK1], tokens[ARG_CRE_PK2], TRUE );
  345.  
  346.     if ( pdata == NULL )
  347.     { /* try to find as pitcher */
  348.         pdata = pdb_pdata( tokens[ARG_CRE_PK1], tokens[ARG_CRE_PK2], FALSE );
  349.     }
  350.  
  351.     if ( pdata != NULL )
  352.     { /* shouldn't happen - set zorch to be FREE agent */
  353.         pdata->zorch = PLAYER_FREE;
  354.     }
  355.  
  356.     /* Set position mask, honoring any old value. */
  357.     pdb_getpos( &nameblk, &m );
  358.     pdb_setpos( &nameblk, m | posmask );
  359.  
  360.     return TRUE;
  361. }
  362. /*
  363.     BOOL minors( int tokcnt, char *tokens[] )
  364.      Add a player to a rotisserie team's minor league reserve.
  365.  
  366.  ACCEPTS:
  367.     int tokcnt - how many tokens on this line
  368.     char *tokens[] - array pointing to each token
  369.  
  370.  RETURNS:
  371.     BOOL <value> - TRUE if everything was okay, FALSE if things really aren't
  372. */
  373.  
  374. BOOL minors ARGLIST( (tokcnt, tokens) )
  375.     NFARG( int tokcnt )
  376.     FARG( char *tokens[] )
  377. {
  378.     return TRUE;
  379. }
  380.  
  381.  
  382.